<template>
  <div class="asideContainer">
    <ul>
      <li @click="toTop" class="iconBox">
        <a class="iconfont icon-xiangshangjiantou"></a>
      </li>
      <li class="iconBox" @mouseover="qrcodeHover" @mouseleave="qrcodeLeave">
        <div v-if="qrcodeShow" class="qrcode"><img src="../assets/logo.png" alt=""></div>
        <a class="iconfont icon-weixin"></a>
      </li>
    </ul>
  </div>
</template>

<script>
export default {
  data () {
    return {
      qrcodeShow: false
    }
  },
  methods: {
    toTop () {
      let top = document.documentElement.scrollTop || document.body.scrollTop
      // 实现滚动效果
      const timeTop = setInterval(() => {
        document.body.scrollTop = document.documentElement.scrollTop = top -= 50
        if (top <= 0) {
          clearInterval(timeTop)
        }
      }, 30)
    },
    qrcodeHover () {
      this.qrcodeShow = true
    },
    qrcodeLeave () {
      this.qrcodeShow = false
    }
  }
}
</script>

<style>
.asideContainer{
  position: fixed;
  top: 50%;
  z-index: 99;
  right: 20px;
  width: 30px;
  height: 100px;
  transform: translate(0 , -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
}
.iconBox{
  position: relative;
  width: 30px;
  height: 30px;
  text-align: center;
  background-color: #fff;
  margin-bottom: 10px;
  line-height: 30px;
  background-color: #fff;
  border: 1px solid #888;
}
.iconBox i{
  width: 100%;
  font-weight: 700;
  color: #6d6d6d;
}
.iconBox:hover{
  background-color: red;
  cursor: pointer;
}
.qrcode{
  box-sizing: border-box;
  position: absolute;
  width: 100px;
  height: 100px;
  left: -110px;
  top: -30px;
  background-color: #fff;
  padding: 10px;
}
.qrcode img{
  width: 80px;
  height: 80px;
}
.qrcode::after{
  display: block;
  position: absolute;
  right: -10px;
  top: 40px;
  width: 0;
  height: 0;
  border-top: 5px solid transparent;
  border-left: 10px solid #fff;
  border-bottom: 5px solid transparent;
  content: '';
}
</style>
